package com.example.dao;

import com.example.pojo.Department;
import com.example.pojo.Employee;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class EmployeeDao {
    @Autowired
    private DepartmentDao departmentDao;

    private static Map<Integer, Employee> employees = null;

    static {
        employees = new HashMap<>();
        employees.put(1001, new Employee(1001,"AA", 1, "153321139@qq.com", new Department(101, "市场部")));
        employees.put(1002, new Employee(1001,"AA", 1, "153321139@qq.com", new Department(102, "教学部")));
        employees.put(1003, new Employee(1001,"AA", 1, "153321139@qq.com", new Department(103, "教研部")));
        employees.put(1004, new Employee(1001,"AA", 1, "153321139@qq.com", new Department(104, "开发部")));
        employees.put(1005, new Employee(1001,"AA", 1, "153321139@qq.com", new Department(105, "后勤部")));
    }

    private static Integer initId = 1006;

    public void save(Employee employee){
        if(employee.getId()==null){
            employee.setId(initId++);
        }

        employees.put(employee.getId(), employee);
    }

    public Collection<Employee> selectAll(){
        return employees.values();
    }

    public Employee selectById(Integer id){
        return employees.get(id);
    }

    public void deleteById(Integer id){
        employees.remove(id);
    }



}
